/**
 * 
 */

var ggmap_map;
var ggmap_geocoder;

function ggmap_click (event)
{
  var latlng = event.latLng;
  var latedit = document.getElementById ("ggmap_lat");
  
  if (latedit)
  {
	  latedit.value = latlng.lat();
  }
  
  var lngedit = document.getElementById ("ggmap_lng");
  if (lngedit)
  {
	  lngedit.value = latlng.lng();
  }
  
  var adredit = document.getElementById ("ggmap_adr");
  if (adredit)
  {
	  if (!ggmap_geocoder)
      {
		  ggmap_geocoder = new google.maps.Geocoder();
      }
	  ggmap_geocoder.geocode ( {'latLng' : latlng }, ggmap_addressreceived) 
  }
  
}

function ggmap_addressreceived (results, status)
{
	var adredit = document.getElementById ("ggmap_adr");
	
    if (status == google.maps.GeocoderStatus.OK)
    {
    	if (results[0])
    	{
    		adredit.value = results[0].formatted_address;
    	}
    }
    else
    {
    	adredit.value = "Geocoder failed: " + status;
    }
}

function ggmap_create (latlng, zoom)
{
	// Common initialization for google maps
	
    var myOptions = {zoom: zoom, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP};
    ggmap_map = new google.maps.Map(document.getElementById("ggmap"), myOptions);
    google.maps.event.addListener (ggmap_map, 'click', ggmap_click);
} 

function ggmap_mark (latlng, title)
{
    var marker = new google.maps.Marker({position: latlng, map: ggmap_map, title: title });    
}